//package cn.lh.conmon;
//
//import com.fasterxml.jackson.annotation.JsonInclude;
//import com.fasterxml.jackson.core.type.TypeReference;
//import com.fasterxml.jackson.databind.DeserializationFeature;
//import com.fasterxml.jackson.databind.JavaType;
//import com.fasterxml.jackson.databind.JsonNode;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.fasterxml.jackson.databind.introspect.Annotated;
//import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
//import com.fasterxml.jackson.databind.ser.FilterProvider;
//import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
//import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
//
//import java.io.Writer;
//import java.util.Optional;
//
//public class JsonConverter {
//    public static final ObjectMapper mapper = new ObjectMapper();
//
//    public JsonConverter() {
//    }
//
//    public static String format(Object obj) {
//        try {
//            return mapper.writeValueAsString(obj);
//        } catch (Exception var2) {
//            throw new RuntimeException("object format to json error:" + obj, var2);
//        }
//    }
//
//    public static void outputToWriter(Writer out, Object value) {
//        try {
//            mapper.writeValue(out, value);
//        } catch (Exception var3) {
//            throw new RuntimeException("output to writer error:" + value, var3);
//        }
//    }
//
//    public static <T> T parse(JsonNode body, Class<T> clz) {
//        try {
//            return mapper.readValue(body.traverse(), clz);
//        } catch (Exception var3) {
//            throw new RuntimeException("json node parse to object [" + clz + "] error:" + body, var3);
//        }
//    }
//
//    public static <T> T parse(String str, Class<T> clz) {
//        try {
//            return mapper.readValue(str == null ? "{}" : str, clz);
//        } catch (Exception var3) {
//            throw new RuntimeException("json parse to object [" + clz + "] error:" + str, var3);
//        }
//    }
//
//    public static <T> T parse(Optional<String> json, Class<T> clz) {
//        return json.map((str) -> {
//            return parse(str, clz);
//        }).orElse((T) null);
//    }
//
//    public static <T> T parse(String str, TypeReference<T> tr) {
//        try {
//            return mapper.readValue(str, tr);
//        } catch (Exception var3) {
//            throw new RuntimeException("json parse to object [" + tr + "] error:" + str, var3);
//        }
//    }
//
//    public static <T> T parse(JsonNode body, JavaType javaType) {
//        try {
//            return mapper.readValue(body.traverse(), javaType);
//        } catch (Exception var3) {
//            throw new RuntimeException("json parse to object [" + body + "] error:" + body, var3);
//        }
//    }
//
//    public static <T> T parse(String str, JavaType javaType) {
//        try {
//            return mapper.readValue(str, javaType);
//        } catch (Exception var3) {
//            throw new RuntimeException("json parse to object [" + str + "] error:" + str, var3);
//        }
//    }
//
//    public static JsonNode tree(Object obj) {
//        try {
//            return mapper.valueToTree(obj);
//        } catch (Exception var2) {
//            throw new RuntimeException("object format to json error:" + obj, var2);
//        }
//    }
//
//    public static String serializeAllExcept(Object obj, String... filterFields) {
//        try {
//            ObjectMapper mapper = new ObjectMapper();
//            mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//            FilterProvider filters = (new SimpleFilterProvider()).addFilter(obj.getClass().getName(), SimpleBeanPropertyFilter.serializeAllExcept(filterFields));
//            mapper.setFilterProvider(filters);
//            mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
//                private static final long serialVersionUID = 2879983075597568303L;
//
//                public Object findFilterId(Annotated ac) {
//                    return ac.getName();
//                }
//            });
//            return mapper.writeValueAsString(obj);
//        } catch (Exception var4) {
//            throw new RuntimeException("object format to json error:" + obj, var4);
//        }
//    }
//
//    public static String filterOutAllExcept(Object obj, String... filterFields) {
//        try {
//            ObjectMapper mapper = new ObjectMapper();
//            mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//            FilterProvider filters = (new SimpleFilterProvider()).addFilter(obj.getClass().getName(), SimpleBeanPropertyFilter.filterOutAllExcept(filterFields));
//            mapper.setFilterProvider(filters);
//            mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
//                private static final long serialVersionUID = -3514739908083561067L;
//
//                public Object findFilterId(Annotated a) {
//                    return a.getName();
//                }
//            });
//            return mapper.writeValueAsString(obj);
//        } catch (Exception var4) {
//            throw new RuntimeException("object format to json error:" + obj, var4);
//        }
//    }
//
//    static {
//        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false).configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true).configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
//    }
//}
